def allPathsSourceTarget(graph):
    def dfs(node, path):
        # 如果当前节点是目标节点，则将当前路径添加到结果列表中
        if node == len(graph) - 1:
            result.append(path)
            return
        # 遍历当前节点的所有邻接节点
        for next_node in graph[node]:
            dfs(next_node, path + [next_node])

    result = []
    dfs(0, [0])  # 从节点 0 开始搜索
    return result

# 测试示例
graph1 = [[1, 2], [3], [3], []]
print(allPathsSourceTarget(graph1))  # 输出: [[0, 1, 3], [0, 2, 3]]

graph2 = [[4, 3, 1], [3, 2, 4], [3], [4], []]
print(allPathsSourceTarget(graph2))  # 输出: [[0, 4], [0, 3, 4], [0, 1, 3, 4], [0, 1, 2, 3, 4], [0, 1, 4]]
# 输出: [[0, 1, 3], [0, 2, 3]]